! 需要链接lapack,blas库
program example
    use matrix_io
    use gerrsim
    implicit none
    real, parameter :: pi = 3.14159265
    ! 刚度矩阵,质量矩阵
    real,allocatable::K(:,:),M(:,:)
    ! 要求的特征值数量
    integer::nev,N,q,i
    real,allocatable::evals(:)
    real,allocatable::evecs(:,:)
    integer :: rows, cols, err
    N=100
    nev=5
    q=min(2*nev,nev+8)
    allocate(K(N,N),M(N,N))
    call loadtxt('M100.txt', M, rows, cols, err)
    call loadtxt('K100.txt', K, rows, cols, err)

    allocate(evals(nev)); allocate(evecs(N,nev))
    call svgerrsim(K,M,N,nev,q,0.00001,evals,evecs)
    ! --------------输出-------------
    print *, "eigen values:"
    do i=1,nev
        print *,i,'mode=', evals(i)
    end do
    print *, "eigen vectors:"
    do i=1,nev
        write(*,'(A,I2,A)') "mode",i," = \n"
        write(*,'(5F10.5)') evecs(:,i)
    end do
    ! 释放空间
    deallocate(K)
    deallocate(M)
    deallocate(evals)
    deallocate(evecs)
end program example